package com.cloudkinto.service.finance.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudkinto.common.DicBusinessItemConstant;
import com.cloudkinto.common.constant.SysConstant;
import com.cloudkinto.common.exception.BizException;
import com.cloudkinto.common.utils.MathUtils;
import com.cloudkinto.common.utils.TimeUtils;
import com.cloudkinto.common.utils.dict.StaticDict;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.dao.*;
import com.cloudkinto.entity.*;
import com.cloudkinto.service.company.CompanyService;
import com.cloudkinto.service.dic.vo.LanguageValueEntity;
import com.cloudkinto.service.file.FileService;
import com.cloudkinto.service.finance.CompanyAccountService;
import com.cloudkinto.service.finance.CostRecordService;
import com.cloudkinto.service.finance.RechargeRecordService;
import com.cloudkinto.service.finance.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * <p>
 * service实现类
 * </p>
 *
 * @author ding
 * @since 2020-06-10
 */
@Service
@Transactional(rollbackFor = Exception.class)//事务回滚
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordDao, RechargeRecordDo> implements RechargeRecordService {
    private static final String MONEY_TYPE_RMB = "0";
    private static final String MONEY_TYPE_JP = "1";
    private static final String MONEY_TYPE_US = "2";
    @Autowired
    private RechargeRecordDao dao;
    @Autowired
    private RechargeTypeDao rechargeTypeDao;
    @Autowired
    private CompanyAccountDao accountDao;
    @Autowired
    private FileService fileService;
    @Autowired
    private CompanyAccountService accountService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private ExchangeRateDao exchangeRateDao;
    @Autowired
    private CompanyDao companyDao;
    @Resource
    private CostRecordService mCostService;

    @Resource
    private InvoiceRecordDao invoiceRecordDao;
    @Resource
    private UserDao userDao;
    @Autowired
    private RoleDao roleDao;
    @Autowired
    private SmsDao smsDao;

    @Override
    public SingleResult addInit(Long companyId) {
        List<Map> rechargeTypeDoList = companyService.getInitList(null);
        Map addInit = new HashMap();
        addInit.put("companyList", rechargeTypeDoList);
//        addInit.put("payType", rechargeTypeDoList);
        List<LanguageValueEntity> idAndNameEntities = new ArrayList<>();
        idAndNameEntities.add(new LanguageValueEntity(MONEY_TYPE_RMB, "人民币"));
        idAndNameEntities.add(new LanguageValueEntity(MONEY_TYPE_JP, "日币"));
        addInit.put("currencyType", idAndNameEntities);
        idAndNameEntities = new ArrayList<>();
        idAndNameEntities.add(new LanguageValueEntity(0, "人民币账户"));
        idAndNameEntities.add(new LanguageValueEntity(1, "日币账户"));
        addInit.put("moneyType", idAndNameEntities);
        return SingleResult.success(addInit);
    }

    @Override
    public Object add(RechargeAddReq rechargeAddReq, Long companyId, Long userId) {
//        SingleResult singleResult = fileService.uploadTempFile(file, userId);
        RechargeRecordDo entityDo = new RechargeRecordDo();
        //实时汇率
        double rate = 0D;
        QueryWrapper exrateWrapper = new QueryWrapper();
        exrateWrapper.orderByDesc("id");
        exrateWrapper.eq("type", DicBusinessItemConstant.CurrencyTypeJpy);
        exrateWrapper.last("limit 1");
        ExchangeRateDo exchangeRate = exchangeRateDao.selectOne(exrateWrapper);
        rate = exchangeRate.getRate();
        entityDo.setId(System.currentTimeMillis());
        entityDo.setRechargeTypeId(0L);//后台充值
        entityDo.setRechargeAccount(1L);
        entityDo.setPayAccount(rechargeAddReq.getPayAccount());
        if (StringUtils.isNotBlank(rechargeAddReq.getPayDate()))
            entityDo.setPayDate(TimeUtils.parseDate(rechargeAddReq.getPayDate()));
        if (MONEY_TYPE_RMB.equals(rechargeAddReq.getCurrency())) {//充值为人民币时选择为0
            entityDo.setCurrency(DicBusinessItemConstant.CurrencyTypeRmb);
            double amountJP = rechargeAddReq.getAmount() / rate;
            entityDo.setAmountJpy(new BigDecimal(amountJP).setScale(0, RoundingMode.HALF_UP).doubleValue());
            entityDo.setAmountRmb(rechargeAddReq.getAmount());
        } else {
            entityDo.setCurrency(DicBusinessItemConstant.CurrencyTypeJpy);
            double amountRMB = rechargeAddReq.getAmount() * rate;
            entityDo.setAmountRmb(new BigDecimal(amountRMB).setScale(2, RoundingMode.HALF_UP).doubleValue());
            entityDo.setAmountJpy(rechargeAddReq.getAmount());
        }
        entityDo.setJpyRate(rate);
        entityDo.setCompanyId(Long.parseLong(rechargeAddReq.getCompanyId()));
        entityDo.setCertificateImageFileId(rechargeAddReq.getFileId() == null ? null : Long.parseLong(rechargeAddReq.getFileId()));
        entityDo.setTips(rechargeAddReq.getTips());
//        BeanUtils.copyProperties(req, entityDo);
        handlerAddBefore(entityDo, userId);
        dao.insert(entityDo);
        return handlerAddAfter(entityDo);
    }

    //做新增之前要执行的业务定制处理
    private void handlerAddBefore(RechargeRecordDo entityDo, Long userId) {
        entityDo.setCreateBy(userId);
        entityDo.setCreateTime(new Date());
        entityDo.setDeleteFlag(SysConstant.DELETE_FLAG_FALSE);
    }

    //将新增的do转换成要返回的实体
    private Object handlerAddAfter(RechargeRecordDo entityDo) {
        //文件操作
        fileService.uploadFile(entityDo.getCertificateImageFileId());
        return null;
    }

    @Override
    public SingleResult updateInit(Long id) {
        return SingleResult.success("");
    }

    @Override
    public Object update(Object req, Long userId) {
        /*RechargeRecordDo entityDo = dao.selectById(req.getId());
        BeanUtils.copyProperties(req, entityDo);
        handlerUpdateBefore(entityDo, userId);
        dao.updateById(entityDo);
        return handlerUpdateAfter(entityDo);*/
        return null;
    }

    //编辑校验
    private void updateCheck(Object req) {

    }

    //做修改之前要执行的业务定制处理
    private void handlerUpdateBefore(RechargeRecordDo entityDo, Long userId) {
//        entityDo.setUpdateBy(userId);
//        entityDo.setUpdateTime(new Date());
    }

    //做修改之后要执行的业务定制处理
    private Object handlerUpdateAfter(RechargeRecordDo entityDo) {
        Object res = new Object();
        BeanUtils.copyProperties(entityDo, res);
        return res;
    }

    @Override
    public int delete(Long id, Long userId) {
        RechargeRecordDo entityDo = dao.selectById(id);
        if ("1".equals(entityDo.getStatus())) {
            throw new BizException(SysConstant.NoPower);
        }
        handlerDeleteBefore(entityDo, userId);
        return dao.deleteById(id);
    }

    //做删除之前要执行的业务定制处理
    private void handlerDeleteBefore(RechargeRecordDo entityDo, Long userId) {
        entityDo.setDeleteBy(userId);
        entityDo.setDeleteTime(new Date());
    }

    @Override
    public Object detail(Long id) {
        RechargeRecordDo entityDo = dao.selectById(id);
        Object res = new Object();
        BeanUtils.copyProperties(entityDo, res);
        return handlerDetailAfter(res);
    }

    //查询明细之后要执行的业务定制处理
    private Object handlerDetailAfter(Object res) {
        return res;
    }

    @Override
    public SingleResult pageInit() {
        Map map = new HashMap();
        List<LanguageValueEntity> mapList = new ArrayList<>();
        List<RechargeTypeDo> rechargeIdList = new ArrayList<>();
        RechargeTypeDo rechargeTypeDo = new RechargeTypeDo();
        rechargeTypeDo.setId(0L);
        rechargeTypeDo.setTypeName("后台充值");
        List<RechargeTypeDo> rechargeTypeDoList = rechargeTypeDao.selectList(null);
        rechargeIdList.add(rechargeTypeDo);
        for (RechargeTypeDo rechargeType :
                rechargeTypeDoList) {
            rechargeType.setCurrency("0".equals(rechargeType.getCurrency())
                    ? DicBusinessItemConstant.CurrencyTypeRmb + "" : DicBusinessItemConstant.CurrencyTypeJpy + "");
            rechargeIdList.add(rechargeType);
        }
        //0 待审核  1充值成功 2充值取消
        mapList.add(new LanguageValueEntity(0, "等待审核"));
        mapList.add(new LanguageValueEntity(1, "充值成功"));
        mapList.add(new LanguageValueEntity(2, "充值取消"));
        map.put("statusList", mapList);
        map.put("rechargeIdList", rechargeIdList);
        return SingleResult.success(map);
    }

    @Override
    public List<RechargeRecordRes> getList(Map<String, String> map) {
        QueryWrapper<RechargeRecordDo> wrapper = queryBuild(map);
        List<RechargeRecordDo> list = this.list(wrapper);
        List<RechargeRecordRes> result = handlerListAfter(list, null);
        return result;
    }

    @Override
    public PageResult<RechargeRecordRes> getListPage(Map<String, String> map) {
        QueryWrapper<RechargeRecordDo> wrapper = queryBuild(map);
        IPage<RechargeRecordDo> page = pageInit(map);
        page = this.page(page, wrapper);
        List<RechargeRecordRes> resList = handlerListAfter(page.getRecords(), null);
        PageResult result = new PageResult(resList, (int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), (int) page.getPages());
        return result;
    }

    //查询分页列表之后对列表数据的处理
    private List<RechargeRecordRes> handlerListAfter(List<RechargeRecordDo> list, Long currency) {
        List<RechargeRecordRes> result = new ArrayList<>();
        for (RechargeRecordDo recordDo : list) {
            RechargeRecordRes recordRes = new RechargeRecordRes();
            BeanUtils.copyProperties(recordDo, recordRes);
            if (recordDo.getCurrency() == null) {
                RechargeTypeDo rechargeTypeDo = rechargeTypeDao.selectById(recordDo.getRechargeTypeId());
                if (rechargeTypeDo != null) {
                    recordRes.setCurrency("0".equals(rechargeTypeDo.getCurrency()) ? DicBusinessItemConstant.CurrencyTypeRmb : DicBusinessItemConstant.CurrencyTypeJpy);
                }
            }
            if (recordDo.getRechargeAccount() == null) {
                recordDo.setRechargeAccount(1L);
            }
            recordRes.setRechargeAccount(recordDo.getRechargeAccount() == 0L ? "人民币账户" : "日币账户");
            recordRes.setPayAccount(recordDo.getPayAccount());
            recordRes.setPayDate(TimeUtils.formatDate(recordDo.getPayDate()));

            RechargeTypeDo rechargeTypeDo = rechargeTypeDao.selectById(recordDo.getRechargeTypeId());
            if (rechargeTypeDo != null) {
                if (rechargeTypeDo.getId() == 3L) {
                    recordRes.setEnableApply(0);
                } else {
                    //不是日本账户 根据币种判断
                    Long rechargeTypeCurrency = "0".equals(rechargeTypeDo.getCurrency()) ? DicBusinessItemConstant.CurrencyTypeRmb : DicBusinessItemConstant.CurrencyTypeJpy;
                    if (currency != null && !currency.equals(rechargeTypeCurrency)) {
                        recordRes.setEnableApply(0);
                    } else {
                        recordRes.setEnableApply(1);
                    }
                }
                recordRes.setPayType(rechargeTypeDo.getTypeName());
            } else {
                recordRes.setPayType("后台充值");
                if (currency != null && !currency.equals(recordDo.getCurrency())) {
                    //币种不匹配
                    recordRes.setEnableApply(0);
                } else {
                    recordRes.setEnableApply(1);
                }

            }

//            if (recordDo.getRechargeTypeId() == 0) {//type  0 是筋斗云后台充值
//                recordRes.setPayType("后台充值");
////                if (recordDo.getCompanyId() == 1) {
//                recordRes.setEnableApply(1);
////                }
//            } else {
//                RechargeTypeDo rechargeTypeDo = rechargeTypeDao.selectById(recordDo.getRechargeTypeId());
//                if (rechargeTypeDo == null) {
//                    recordRes.setPayType("后台充值");
//                    if (recordDo.getCompanyId() == 1) {
//                        recordRes.setEnableApply(1);
//                    }
//                } else {
//                    if ("0".equals(rechargeTypeDo.getCurrency())) {
//                        recordRes.setEnableApply(1);
//                    } else {
//                        recordRes.setEnableApply(0);
//                    }
//                    recordRes.setPayType(rechargeTypeDo.getTypeName());
//                }
//            }
            recordRes.setAmountJp(recordDo.getAmountJpy());
            recordRes.setAmountRmb(recordDo.getAmountRmb());
            recordRes.setInvoiceRecordId(recordDo.getInvoiceRecordId());

            CompanyDo companyDo = companyDao.selectById(recordDo.getCompanyId());
            if (companyDo != null) {
                recordRes.setCompanyCode(companyDo.getCompanyCode());
            }

            recordRes.setStatus(getStatusMap().get(recordDo.getStatus()));
            FileDo fileDo = fileService.getBaseMapper().selectById(recordDo.getCertificateImageFileId());
            if (fileDo != null) {
                recordRes.setCertificateImagePath(fileService.getFilePath(recordDo.getCertificateImageFileId()));
                recordRes.setCertificateImage(fileDo.getFileName() + fileDo.getFileSuffix());
            }
            result.add(recordRes);
        }
        return result;
    }

    private Map<String, String> getStatusMap() {
        Map<String, String> statusMap = new HashMap();
        //0 待审核  1充值成功 2充值取消
        statusMap.put("0", "等待审核");
        statusMap.put("1", "充值成功");
        statusMap.put("2", "充值取消");
        return statusMap;
    }

    private IPage<RechargeRecordDo> pageInit(Map<String, String> map) {
        IPage<RechargeRecordDo> page = new Page();
        page.setSize(StringUtils.isNotBlank(map.get("pageSize")) ? Long.parseLong(map.get("pageSize")) : 10);
        page.setCurrent(StringUtils.isNotBlank(map.get("current")) ? Long.parseLong(map.get("current")) : 1);
        return page;
    }

    private QueryWrapper<RechargeRecordDo> queryBuild(Map<String, String> map) {
        QueryWrapper<RechargeRecordDo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(map.get("startDate"))) {
            wrapper.ge("create_time", map.get("startDate"));
        }
        if (StringUtils.isNotBlank(map.get("endDate"))) {
            wrapper.lt("create_time", TimeUtils.addDaysFormat(map.get("endDate"), "yyyy-MM-dd", 1));
        }
        if (StringUtils.isNotBlank(map.get("type"))) {
            wrapper.eq("status", map.get("type"));
        }
        if (StringUtils.isNotBlank(map.get("companyId"))) {
            wrapper.eq("company_id", map.get("companyId"));
        }
        if (StringUtils.isNotBlank(map.get("matchType"))) {
            if ("0".equals(map.get("matchType"))) {
                wrapper.isNull("invoice_record_id");
            } else {
                wrapper.isNotNull("invoice_record_id");
                wrapper.in("recharge_type_id", 1, 2, 4, 5);
            }
        }
        if (StringUtils.isNotBlank(map.get("rechargeTypeId"))) {
            wrapper.eq("recharge_type_id", map.get("rechargeTypeId"));
        }
        if (StringUtils.isNotBlank(map.get("doubleCheck"))) {
            wrapper.eq("double_check", map.get("doubleCheck"));
            wrapper.eq("status", 1);
        }
        wrapper.orderByDesc("id");
        return wrapper;
    }

    @Override
    public PageResult<RechargeRecordRes> matchInvoiceList(Map<String, String> map) {
        if (StringUtils.isBlank(map.get("currency"))) {
            throw new BizException(SysConstant.Pls_Amount_Type);
        }
        QueryWrapper<RechargeRecordDo> wrapper = queryBuild(map);
        IPage<RechargeRecordDo> page = pageInit(map);
        page = this.page(page, wrapper);
        Long currency = null;
        if (StringUtils.isNotBlank(map.get("currency"))) {
            currency = Long.parseLong(map.get("currency"));
        }
        List<RechargeRecordRes> resList = handlerListAfter(page.getRecords(), currency);
        PageResult result = new PageResult(resList, (int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), (int) page.getPages());
        return result;
    }

    @Override
    public Integer getUnCheckCount(Long companyId) {
        LambdaQueryWrapper<RechargeRecordDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RechargeRecordDo::getDoubleCheck, 0);
        wrapper.eq(RechargeRecordDo::getStatus, 1);
        wrapper.ge(RechargeRecordDo::getCreateTime, TimeUtils.getCurrentDateFormat(-90));
        if (companyId != null) {
            wrapper.eq(RechargeRecordDo::getCompanyId, companyId);
        }
        return dao.selectCount(wrapper);
    }


    @Override
    public Integer getUnExamineCount(Long companyId) {
        LambdaQueryWrapper<RechargeRecordDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RechargeRecordDo::getStatus, 0);
        wrapper.ge(RechargeRecordDo::getCreateTime, TimeUtils.getCurrentDateFormat(-90));
        if (companyId != null) {
            wrapper.eq(RechargeRecordDo::getCompanyId, companyId);
        }
        return dao.selectCount(wrapper);
    }

    @Override
    public String checkPass(RechargeRecordCheckReq req, Long userId) {
        Double afterBalance = 0D;
        RechargeRecordDo recordDo = baseMapper.selectByIdForUpdate(req.getId());
        if (req.getAmountJpy() != null && req.getAmountJpy() != 0)
            recordDo.setAmountJpy(req.getAmountJpy());
        if (req.getAmountRmb() != null && req.getAmountRmb() != 0)
            recordDo.setAmountRmb(req.getAmountRmb());
        if (req.getPayType() != null && req.getPayType() != 0)
            recordDo.setRechargeTypeId(req.getPayType());
        if (recordDo == null) {
            throw new BizException(SysConstant.Error_Record_Notfound);
        }
        if (!"0".equals(recordDo.getStatus()) && req.getRoleType() != 1) {
            throw new BizException(SysConstant.RechargeRecord_Error_HadDeal);
        }

        if (recordDo.getDoubleCheck() == 1) {
            throw new BizException(SysConstant.NoPower);
        }

        if ("2".equals(recordDo.getStatus()) && req.getRoleType() == 1) {
            throw new BizException(SysConstant.NoPower);
        } else if ("0".equals(recordDo.getStatus()) && req.getRoleType() == 1) {
            //等待审核 状态，且财务直接确认
            afterBalance = accountService.addAmount(recordDo);
            recordDo.setEntryTime(new Date());
            recordDo.setEntryBy(userId);
            recordDo.setAfterAmount(afterBalance);
        }

        recordDo.setUpdateBy(userId);
        recordDo.setUpdateTime(new Date());
        recordDo.setStatus(req.getType() + "");
        if (req.getJpyRate() != null) {
            recordDo.setJpyRate(req.getJpyRate());
        }
        if (recordDo.getRechargeAccount() == null) {
            recordDo.setRechargeAccount(1L);
        }
        if (recordDo.getRechargeTypeId() == 0L) {
            if (recordDo.getCurrency() != null) {
                //后台充值
                if (DicBusinessItemConstant.CurrencyTypeRmb.equals(recordDo.getCurrency())) {
                    //人名币
                    recordDo.setAmountJpy(MathUtils.div(0, recordDo.getAmountRmb(), recordDo.getJpyRate() == null ? 1 : recordDo.getJpyRate()));
                } else {
                    recordDo.setAmountRmb(MathUtils.numberFormat(2, MathUtils.mul(recordDo.getAmountJpy(), recordDo.getJpyRate() == null ? 1 : recordDo.getJpyRate())));
                }
            }
        } else {
            RechargeTypeDo rechargeTypeDo = rechargeTypeDao.selectById(recordDo.getRechargeTypeId());
            if (rechargeTypeDo == null) {
                throw new BizException(SysConstant.RechargeRecord_Type_Incorrect);
            }
            //如果重置的是人民币账户 ，则把日币按照汇率重新算
            if ("0".equals(rechargeTypeDo.getCurrency())) { //人民币
                recordDo.setAmountJpy(MathUtils.div(0, recordDo.getAmountRmb(), recordDo.getJpyRate() == null ? 1 : recordDo.getJpyRate()));
            } else {
                recordDo.setAmountRmb(MathUtils.numberFormat(2, MathUtils.mul(recordDo.getAmountJpy(), recordDo.getJpyRate() == null ? 1 : recordDo.getJpyRate())));
            }
        }
        updateById(recordDo);


        if (req.getRoleType() == 1) {
            UserDo userDo = userDao.selectById(userId);
            RoleDo roleDo = roleDao.selectById(userDo.getRoleId());
            if (roleDo == null || !(SysConstant.clientAdmin.equals(roleDo.getDevCode()) || SysConstant.serverAdmin.equals(roleDo.getDevCode()) || SysConstant.serverFinance.equals(roleDo.getDevCode()))) {
                throw new BizException(SysConstant.NoPower);
            }
            //admin审核
            if (req.getType() == 2) { //财务确认 取消 账户扣除充值金额
                afterBalance = accountService.costAmount(recordDo.getCompanyId() + "", recordDo.getAmountJpy(), 1);
                recordDo.setTips(recordDo.getTips() + (StringUtils.isNotBlank(recordDo.getTips()) ? ";" : "") + "财务审核退回");
            } else {
                afterBalance = recordDo.getAfterAmount();
            }
            recordDo.setDoubleCheck(1);
            recordDo.setDoubleCheckTime(new Date());
        } else if (req.getType() == 1) {
            afterBalance = accountService.addAmount(recordDo);
            recordDo.setEntryTime(new Date());
            recordDo.setEntryBy(userId);
        }
        recordDo.setAfterAmount(afterBalance);

        updateById(recordDo);
        return "";
    }

    @Override
    public void matchSmsList() {
        List<RechargeRecordDo> rechargeRecordDos = dao.selectList(new LambdaQueryWrapper<RechargeRecordDo>()
                .isNotNull(RechargeRecordDo::getCurrency)
                .le(RechargeRecordDo::getStatus, 1)
                .ne(RechargeRecordDo::getEntryType, 1)
        );
        LambdaQueryWrapper<SmsDo> wrapper = new LambdaQueryWrapper<SmsDo>().eq(SmsDo::getActiveFlag, 0);
        wrapper.isNotNull(SmsDo::getAmount);
        List<SmsDo> smsDos = smsDao.selectList(wrapper);

        for (RechargeRecordDo rechargeRecordDo : rechargeRecordDos) {
            List<SmsDo> collect = smsDos.stream().filter(smsDo -> {
                if (rechargeRecordDo.getCurrency() == 107) {
                    return smsDo.getAmount().intValue() == rechargeRecordDo.getAmountRmb() * 100;
                } else if (rechargeRecordDo.getCurrency() == 108) {
                    return smsDo.getAmount().intValue() == rechargeRecordDo.getAmountJpy() * 100;
                }
                return false;
            }).collect(Collectors.toList());
            if (collect.size() > 0) {
                for (int i = 0; i < collect.size(); i++) {
                    SmsDo smsDo = collect.get(i);
                    if (smsDo.getAmount() % 100000 == 0) {
                        if (smsDo.getPayTime() == null || rechargeRecordDo.getPayDate() == null) continue;
                        if (smsDo.getPayTime().compareTo(rechargeRecordDo.getPayDate()) < 1000 * 60 * 60 * 24
                                && smsDo.getOutAccountName().equals(rechargeRecordDo.getPayAccount())) {

                        } else {
                            continue;
                        }
                    } else if (smsDo.getAmount() % 10000 == 0) {
                        if (smsDo.getPayTime() == null || rechargeRecordDo.getPayDate() == null) continue;
                        if (smsDo.getPayTime().compareTo(rechargeRecordDo.getPayDate()) < 1000 * 60 * 60 * 72
                                || smsDo.getOutAccountName().equals(rechargeRecordDo.getPayAccount())) {

                        } else {
                            continue;
                        }
                    }
                    smsDo.setActiveFlag(1);
                    smsDo.setUpdateBy(1L);
                    smsDo.setUpdateTime(new Date());
                    smsDao.updateById(smsDo);
                    RechargeRecordCheckReq req = new RechargeRecordCheckReq();
                    req.setId(rechargeRecordDo.getId());
                    req.setAmountJpy(rechargeRecordDo.getAmountJpy());
                    req.setAmountRmb(rechargeRecordDo.getAmountRmb());
                    req.setPayType(rechargeRecordDo.getRechargeTypeId());
                    if (smsDo.getOutAccountName().contains("需要确认")) {
                        req.setType(2);
                    } else {
                        req.setType(1);
                    }
                    req.setJpyRate(rechargeRecordDo.getJpyRate());
//                    checkPass(req, null);
                    rechargeRecordDo.setEntryType(1);
                    updateById(rechargeRecordDo);
                }

            }
        }
    }
}
